package com.example.day5_vp;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class MyAdapter extends PagerAdapter {
    List<View> list;

    public MyAdapter(List<View> list) {
        this.list = list;
    }
    //获取数量
    @Override
    public int getCount() {
        return list.size();
    }
    //判断view和object是否为同一个
    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }
    //实例化view
    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);//返回实际的view
    }

    //销毁view
    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        //super.destroyItem(container, position, object);
        container.removeView(list.get(position));
    }

}
